package com.ly.drivingschool.controller;

import com.ly.drivingschool.common.ResponseMessage;
import com.ly.drivingschool.dao.CountDao;
import com.ly.drivingschool.dao.OrderDao;
import com.ly.drivingschool.dao.StaffDao;
import com.ly.drivingschool.dao.UserDao;
import com.ly.drivingschool.pojo.EchartsParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * 前台数据汇总 数据柱形图分析
 */
@RestController // 等同于！@ResponseBody + @Controller
@RequestMapping(value = "count",produces = "application/json; charset=utf-8")
public class CountController {
    @Autowired
    private CountDao countDao;

    // count/dataCount
    @GetMapping(value="dataCount")
    public ResponseMessage dataCount(){
        // 初始化数据
        int userCount = -1; // 注册用户总量
        int orderCount = -1; // 订单总量(相当于订单在校学员总量)
        int addOrderCount = -1; // 新增订单总量
        int staff01Count = -1; // 在职教练总量

        // 获取今天的日期
//        String jt = new SimpleDateFormat("yyyyMMdd").format(new Date());
        // 获取昨天的日期
        Calendar cal=Calendar.getInstance();
        cal.add(Calendar.DATE,-1);
        Date time=cal.getTime();
        String zt = new SimpleDateFormat("yyyyMMdd").format(time);

        // 获取数据
        userCount = countDao.userCount();
        orderCount = countDao.orderCount();
        addOrderCount = orderCount - countDao.timeCount(zt);
        staff01Count = countDao.staffCount("021");

        // 封装数据
        HashMap<String, Integer> dataCount = new HashMap<>();
        dataCount.put("userCount", userCount); 
        dataCount.put("orderCount", orderCount);
        dataCount.put("addOrderCount", addOrderCount);
        dataCount.put("staff01Count", staff01Count);
        return ResponseMessage.createBySuccess("驾校统计分析数据",dataCount);
    }

    /**
     * 图表数据 套餐信息，套餐对应数量
     * @return
     */
    @GetMapping(value = "getEchartsData")
    public ResponseMessage getEchartsData(){
        List<EchartsParam> echartsParamList = countDao.getEchartsData();
        System.out.println(echartsParamList);
        return ResponseMessage.createBySuccess("图表数据",echartsParamList);
    }
}
